-- UIDungeonHpAlert
-- create by zouyb
-- 地牢中血量预警

-- UIDungeonHpAlert继承自Layer
UIDungeonHpAlert = class("UIDungeonHpAlert", function()
    return cc.Layer:create();
end);

function UIDungeonHpAlert.create()
    return UIDungeonHpAlert.new();
end

local resize;

-- 构造函数
function UIDungeonHpAlert:ctor()
    self:setName("UIDungeonHpAlert");

    local node = cc.CSLoader:createNode("layout/dungeon/DungeonHpAlert.csb");
    self:addChild(node);
    self.node = node;

    self:setLocalZOrder(UIMgr.TOP_MENU_ZORDER + 2);

    local duration = 1;

    for i = 1, 4 do
        local bg = findChildByName(node, "CT/bg" .. i);

        -- 初始置为不可见
        bg:setOpacity(0);

        -- 循环进行渐现渐隐
        local callFunc = cc.CallFunc:create(function()
                -- 播放音效
                AudioM.playFx("hazard_warning");
        end)

        if i == 1 then
                bg:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeOut:create(duration), callFunc, cc.FadeIn:create(duration))));
        else
                bg:runAction(cc.RepeatForever:create(cc.Sequence:create(cc.FadeOut:create(duration), cc.FadeIn:create(duration))));
        end
    end

    resize(node);

end

-- 适配
resize = function(node)
    local w = AlignM.frameSize.width;
    local h = AlignM.frameSize.height;
    node:setContentSize(w, h);

    local  ct = findChildByName(node, "CT");
    ct:setPosition(w / 2, h / 2);
    ct:setScaleX(w / DESIGN_WIDTH);
        ct:setScaleY(h / DESIGN_HEIGHT);
end

